package VUTHANHPHUC_HOMEWORK_OOP;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class RegisView extends JFrame {

	private JPanel contentPane;
	private JTextField txtTen;
	private JTextField txtTuoi;
	private JTextField txtKQ;
	private JComboBox cboHN;
	private JComboBox cboGT;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RegisView frame = new RegisView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public RegisView() {
		setTitle("Đăng ký thma gia kết bạn");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 442, 350);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Nhập thông tin theo yêu cầu");
		lblNewLabel.setBounds(10, 11, 161, 14);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Nhập tên của bạn");
		lblNewLabel_1.setBounds(10, 45, 161, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Tuổi của bạn");
		lblNewLabel_2.setBounds(10, 76, 161, 14);
		contentPane.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Tình trạng hôn nhân");
		lblNewLabel_3.setBounds(10, 107, 161, 14);
		contentPane.add(lblNewLabel_3);
		
		JLabel lblGiiTnh = new JLabel("Giới tính");
		lblGiiTnh.setBounds(10, 138, 161, 14);
		contentPane.add(lblGiiTnh);
		
		JLabel lblKtQung = new JLabel("Kết quả đăng ký");
		lblKtQung.setBounds(10, 206, 161, 14);
		contentPane.add(lblKtQung);
		
		txtTen = new JTextField();
		txtTen.setBounds(181, 42, 213, 20);
		contentPane.add(txtTen);
		txtTen.setColumns(10);
		
		txtTuoi = new JTextField();
		txtTuoi.setColumns(10);
		txtTuoi.setBounds(181, 73, 173, 20);
		contentPane.add(txtTuoi);
		
		txtKQ = new JTextField();
		txtKQ.setColumns(10);
		txtKQ.setBounds(181, 178, 213, 71);
		contentPane.add(txtKQ);
		
		cboHN = new JComboBox();
		cboHN.setModel(new DefaultComboBoxModel(new String[] {"Đã kết hôn", "Chưa kết hôn", "Đã li hôn"}));
		cboHN.setBounds(181, 104, 173, 20);
		contentPane.add(cboHN);
		
		cboGT = new JComboBox();
		cboGT.setModel(new DefaultComboBoxModel<>(new String[] {"Nam", "Nữ"}));
		cboGT.setBounds(181, 135, 173, 20);
		contentPane.add(cboGT);
		
		JButton DK = new JButton("Đăng ký tham gia");
		DK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(txtTen.getText().isEmpty()){
					JOptionPane.showMessageDialog(getParent(), "Yêu cầu nhập tên", "Lỗi", JOptionPane.ERROR_MESSAGE);
				}else if(txtTuoi.getText().isEmpty()){
					JOptionPane.showMessageDialog(getParent(), "Yêu cầu nhập tuổi", "Lỗi", JOptionPane.ERROR_MESSAGE);
				}else{
					Regis objR = new Regis();
					int age = Integer.parseInt(txtTuoi.getText());
					objR.setAge(age);
					objR.setName(txtTen.getText());
					String opt1 = cboHN.getSelectedItem().toString();
					objR.setRela(opt1);
					String opt2 = cboGT.getSelectedItem().toString();
					objR.setSex(opt2);
					RegisControllers objC = new RegisControllers(objR);
					
				}
			}
		});
		DK.setBounds(262, 265, 132, 23);
		contentPane.add(DK);
	}
}
